package com.jaychen.tliaswebmanagement.mapper;

import com.jaychen.tliaswebmanagement.pojo.Emp;
import com.jaychen.tliaswebmanagement.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

    /**
     此处分页查询不需考虑任何分页操作：PageHelper自动完成
     */
    //@Select("select e.*,d.name from emp e left join dept d on e.dept_id = d.id order by e.update_time desc")
    //public List<Emp> list(String name, Integer gender, LocalDateTime begin, LocalDateTime end);
    List<Emp> list(EmpQueryParam empQueryParam);

    @Options(useGeneratedKeys = true,keyProperty = "id") //获取生成的主键 -- 主键返回
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);

    Emp getById(Integer id);

    void updateById(Emp emp);

    @MapKey("pos")
    List<Map<String,Object>> countEmpJobData();

    @MapKey("name")
    List<Map<String,Object>> countGenderData();

    @Select("select count(*) from emp where dept_id=#{deptId}")
    int getByDeptId(Integer deptId);
}
